// 方法一：排序
// Created by madison on 2022/11/16.
//

#include "string"
#include "vector"

using namespace std;

class Solution {
public:
    string largestNumber(vector<int> &nums) {
        sort(nums.begin(), nums.end(), [](const int &x, const int &y) {
            long sx = 10, sy = 10;
            while (sx <= x) {
                sx *= 10;
            }
            while (sy <= y) {
                sy *= 10;
            }
            return sy * x + y > sx * y + x;
        });
        if (nums[0] == 0) {
            return "0";
        }
        string ret;
        for (int &x: nums) {
            ret += to_string(x);
        }
        return ret;
    }
};

int main() {
    Solution solution;
    vector<int> nums = {3, 30, 34, 5, 9};
    string ret = solution.largestNumber(nums);
    printf("%s\n", ret.c_str());
    return 0;
}